
public class test {

	    public static int lengthOfLongestSubstring(String s) {
	        int start=0;
	        int nLastMax=0;
	        int nCurLen=1;
	        
	        if(s.length()==0)
	        {
	        	return 0;
	        }
	        
	        for(int end=1;end<s.length();end++)
	        {
	            boolean bEqual=false;
	            
	            for(int i=start;i<end;i++)
	            {
	               if(s.charAt(i)==s.charAt(end))
	               {
	                   bEqual=true;
	                   
	                   if(nCurLen>nLastMax)
	                   {
	                     nLastMax=nCurLen;  
	                   }
	                   start=i+1;
	                   nCurLen=(end-start)>0?end-start+1:1;
	                   break;
	               }
	            }
	            
	            if(!bEqual)
	            {
	            	nCurLen++;
	            }
	        }
	        
	        if(nCurLen>nLastMax)
	        {
	        	nLastMax=nCurLen;
	        }
	        return nLastMax;
	    }
	    

	    public static ListNode mergeKLists(ListNode[] lists) {
	           
	        ListNode[] nodes=new ListNode[lists.length];
	        ListNode start=null;
	        ListNode current=null;
	        
	        for(int i=0;i<lists.length;i++)
	        {
	            nodes[i]=lists[i];
	        }
	        
	        ListNode nextnode=getNext(nodes);
	        
	        while(nextnode!=null)
	        {
	            if(start==null)
	            {
	                start=nextnode;
	                current=nextnode;
	            }
	            else
	            {
	                 current.next=nextnode;
	                 current=nextnode;
	            }
	           nextnode=getNext(nodes);
	        }
	        
	        return start;
	    }
	    
	    public static class ListNode {
	    	     int val;
	    	     ListNode next;
	    	      ListNode(int x) { val = x; }
	    	 }
	    private static ListNode getNext(ListNode[] nodes)
	    {
	        ListNode minNode=null;
	        int nMin=Integer.MAX_VALUE;
	        int nMinIndex=-1;
	        for(int i=0;i<nodes.length;i++)
	        {
	            if(nodes[i]!=null && nMin>nodes[i].val)
	            {
	            	nMinIndex=i;
	                nMin=nodes[i].val;
	            }
	        }
	        
	        if(nMinIndex!=-1)
	        {
	             minNode=nodes[nMinIndex];
	             nodes[nMinIndex]=nodes[nMinIndex].next;
	        }
	        
	        return minNode;
	    }
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ListNode[] lists=new ListNode[3];
		lists[0]=new ListNode(1);
		lists[0].next=new ListNode(4);
		lists[0].next.next=new ListNode(5);
		
		lists[1]=new ListNode(1);
		lists[1].next=new ListNode(3);
		lists[1].next.next=new ListNode(4);

		
		lists[2]=new ListNode(2);
		lists[2].next=new ListNode(6);
		
		ListNode node=mergeKLists(lists);
	}

}
